package net.borderwars.util;

import java.util.HashMap;

/**
 * User: Hubbard
 * Date: Feb 24, 2006
 * Time: 3:04:54 PM
 */
public class DoubleMap<Key1, Key2, Value> {
    private HashMap<Key1, HashMap<Key2, Value>> data = new HashMap<Key1, HashMap<Key2, Value>> ();

    public void put (Key1 a, Key2 b, Value v) {
        HashMap<Key2, Value> second = data.get (a);
        if (second == null) {
            second = new HashMap<Key2, Value> ();
            data.put (a, second);
        }
        second.put (b, v);
    }

    public Value remove (Key1 a, Key2 b) {
        HashMap<Key2, Value> second = data.get (a);
        if (second != null) {
            return (second.remove (b));
        }
        return (null);
    }

    public boolean exists (Key1 a, Key2 b) {
        if (get (a, b) == null) {
            return (false);
        }
        return (true);
    }

    public Value get (Key1 a, Key2 b) {
        HashMap<Key2, Value> second = data.get (a);
        if (second == null) {
            return (null);
        }
        return (second.get (b));
    }

}
